from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings


def encrypts(openid):
    """加密函数"""
    serializer =Serializer(settings.SECRET_KEY,600)
    # 创建加密/解密对象
    dirt_data = {"data":openid}
    encrypt_data = serializer.dumps(dirt_data)
    # 对数据进行加密  返回bite类型数据

    return encrypt_data.decode()


def decrypts(openid):
    """解密函数"""
    serializer = Serializer(settings.SECRET_KEY,600)
    # 创建加密/解密对象
    data = serializer.loads(openid)
    # 对数据进行解密  返回字典类型
    return data.get("data")

